{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MyBatisSql处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "from pandas import DataFrame,Series\n",
    "import xlrd\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2、数据处理\n",
    "def doData(sData,cData):\n",
    "  ret = ''\n",
    "  dyl = ' \\''\n",
    "  dyr = '\\' '\n",
    "\n",
    "  arr = sData.split('?')\n",
    "  i = cData.find('Parameters') + len('Parameters:')\n",
    "  parameters = cData[i:]\n",
    "  sArr = parameters.split(',')\n",
    "  for i in range(len(arr)):\n",
    "    s = arr[i].strip()\n",
    "    if i == 0:\n",
    "      ret = s[s.find('Preparing') + len('Preparing:'): ]\n",
    "    else:\n",
    "      p = sArr[i-1]\n",
    "      c = p[:p.find('(')].strip()     # 参数\n",
    "      t = p[p.find('(')+1:p.find(')')].strip()   # 类型\n",
    "      ret = ret + dyl + c + dyr + s\n",
    "  return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "select INIT_BAIL.id, INIT_BAIL.FUT_PRICE_ID, INIT_BAIL.Receipt_Del_Id, RECEIPT.REQUISITION_NO,/**申请单号**/ INIT_BAIL.ADD_BAIL_DATE,/**追加保证金日期**/ INIT_BAIL.Add_Bail_Amount,/**追加保证金金额**/ RECEIPT_DEL.FUT_BAIL_REMAINING_AMT as canAmount,/**可用保证金**/ RECEIPT_DEL.RECEIPT_DATE,/**认领时间**/ RECEIPT.Currency/**币种**/ from WB_TBL_FUT_INIT_BAIL INIT_BAIL inner join WB_TBL_PAY_RECEIPT_DEL RECEIPT_DEL on RECEIPT_DEL.id = INIT_BAIL.RECEIPT_DEL_ID and RECEIPT_DEL.Delete_Flag = '0' inner join WB_TBL_PAY_RECEIPT RECEIPT on RECEIPT.id = RECEIPT_DEL.REQUISITION_ID and RECEIPT.Delete_Flag = '0' where INIT_BAIL.Fut_Price_Id = '1368' order by RECEIPT_DEL.RECEIPT_DATE\n"
    }
   ],
   "source": [
    "# 1、读取数据\n",
    "with open('open.txt','r',encoding='utf-8') as f:\n",
    "    dataArr = f.readlines()\n",
    "    sData = ''       # 带问号的SQL\n",
    "    cData = ''      # 参数\n",
    "    for i in dataArr:\n",
    "        if (i.find('Parameters') >= 0):\n",
    "            cData = i\n",
    "            break\n",
    "        else:\n",
    "            # sData += i.strip()     # 因为eclipse打印出来的log每一行会有个空格。。。\n",
    "            sData += i[:-1]     # 因为eclipse打印出来的log每一行会有个空格。。。\n",
    "    ret = doData(sData,cData)\n",
    "\n",
    "print(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37164bit8719ae96e4cc4b4bb775bda64dd4d4db",
   "display_name": "Python 3.7.1 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}